package com.example.demo.utli;

import com.example.demo.bean.ErrorCode;
import com.example.demo.bean.ThisSystemException;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 费浩东
 * 2018/11/2
 * Created by fhd
 */

public class PwdUtil {
    public static void judgePassWord(String password,String confirm) {
        judgePassWord(password);
        if (!password.equals(confirm)){
            throw new ThisSystemException(ErrorCode.VALUE_ATYPISM.getText(),ErrorCode.VALUE_ATYPISM.getStatus());
        }
    }

    public static void judgePassWord(String password) {
        Matcher chinese = Pattern.compile("[\u4e00-\u9fa5]").matcher(password);
        if (chinese.matches()) {
            throw new ThisSystemException(ErrorCode.CAN_NOT_CONTAIN_CHINESE.getText(),ErrorCode.CAN_NOT_CONTAIN_CHINESE.getStatus());
        }
        Matcher letter=Pattern.compile(".*[a-zA-Z]+.*").matcher(password);
        Matcher number = Pattern.compile(".*\\d+.*").matcher(password);
        if (!letter.matches() || !number.matches()) {
            throw new ThisSystemException(ErrorCode.NUMBER_AND_LETTER.getText(),ErrorCode.NUMBER_AND_LETTER.getStatus());
        }
        if (password.length() < 8 || password.length() > 16 ){
            throw new ThisSystemException(ErrorCode.JUDGE_PASSWORD_LENTH.getText(),ErrorCode.JUDGE_PASSWORD_LENTH.getStatus());
        }
    }

}
